<?php

class MaterialKeywordWithParamAction extends Action {
	
	public function add($module, $content, $keyword,$materialId) {
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		// 初始化模型
		$MaterialKeyword = D("material_keyword_with_param");
		$data["module"] = $module;
		$data["content"] = $content;
		$data["keyword"] = $keyword;
		$data["materialId"] = $materialId;
		$data["updateTime"] = date("Y-m-d H:i:s");
		$result = $MaterialKeyword->add($data);
		if ($result) {
			$data["id"] = $result;
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function update($id, $module, $content, $keyword) {
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		// 初始化模型
		$MaterialKeyword = D("material_keyword_with_param");
		$data["module"] = $module;
		$data["content"] = $content;
		$data["keyword"] = $keyword;
		$data["updateTime"] = date("Y-m-d H:i:s");
		$result = $MaterialKeyword->where("id=$id")->save($data);
		if ($result !==false) {
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	
	public function delete($id){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		// 初始化模型
		$MaterialKeyword = D("material_keyword_with_param");
		$data["updateTime"] = date("Y-m-d H:i:s");
		$data["deleted"] = 1;
		
		$result = $MaterialKeyword->where("id=$id")->save($data);
		if ($result !==false) {
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function getKeywordParamByMaterialId($mid){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		//$module,$tag=''
		$MaterialKeywordParam = D("material_keyword_with_param");
		$condition['materialId'] = array('eq',$mid);
		$condition['deleted'] = array('eq',0);
		 
		$result = $MaterialKeywordParam->where($condition)->find();
		 
		if($result){
			Output::instance()->object($result);
		}else{
			Output::instance()->resultCode(code_custom_error,"没有数据");
		}
	}
}